package com.megoc.menu.adapter;

import android.content.Context;
import android.net.Uri;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.facebook.drawee.view.SimpleDraweeView;
import com.megoc.menu.R;
import com.megoc.menu.model.BaseList;
import com.megoc.menu.model.find.FindAd;

/**
 * Created by Megoc on 2015/10/12.
 */
public class FindHeaderPagerAdapter extends PagerAdapter {
    private Context mContext;
    private java.util.List<FindAd> lists;

    public FindHeaderPagerAdapter(java.util.List<FindAd> lists, Context context) {
        this.lists = lists;
        this.mContext = context;
    }

    @Override
    public int getCount() {
        return lists.size();
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view.equals(object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.item_menu_header_viewpager, container, false);
        SimpleDraweeView simpleDraweeView = (SimpleDraweeView) view.findViewById(R.id.menu_header_viewpager_img);
        TextView textView = (TextView) view.findViewById(R.id.menu_header_viewpager_text);
        Uri uri = Uri.parse(lists.get(position).getImgUrl());
        simpleDraweeView.setImageURI(uri);
        String title=lists.get(position).getTitle();
        if (!TextUtils.isEmpty(title)){
            textView.setVisibility(View.VISIBLE);
            textView.setText(title);
        }else {
            textView.setVisibility(View.GONE);
        }

        ((ViewPager) container).addView(view, 0);
        return view;
    }

    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }
}
